package com.dc.system.controller;

import com.dc.common.model.BaseModel;
import com.dc.system.model.SysDept;
import com.dc.system.model.SysOrgan;
import com.dc.system.service.SysDeptService;
import com.github.pagehelper.PageInfo;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: SysDeptController
 * @Author: ChenXueLi
 * @Date: 2018-05-05 9:44
 */
@Controller
@RequestMapping("/system/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @ApiOperation(value = "添加部门", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "部门名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fk_parent_id", value = "上级部门id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fk_header_id", value = "部门负责人id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fk_contacts_id", value = "部门联系人id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "telephone", value = "联系电话", required = true, paramType = "query"),
            @ApiImplicitParam(name = "functions", value = "部门智能", required = true, paramType = "query"),
            @ApiImplicitParam(name = "order_code", value = "排序", required = false, paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", required = true, paramType = "query"),
            @ApiImplicitParam(name = "memo", value = "备注", required = true, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = false, paramType = "query")
    })
    @RequestMapping("/addSysDept")
    @ResponseBody
    public BaseModel addSysDept(SysDept sysDept, SysOrgan sysOrgan, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysDeptService.addSysDept(sysDept, sysOrgan, baseModel, request);
    }

    @ApiOperation(value = "根据id删除部门", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dept_id", value = "部门id", required = true, paramType = "query")
    })
    @RequestMapping("/deleteSysDeptById")
    @ResponseBody
    public BaseModel deleteSysDeptById(SysDept sysDept, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysDeptService.deleteSysDeptById(sysDept, baseModel, request);
    }

    @ApiOperation(value = "修改部门", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dept_id", value = "部门id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fk_parent_id", value = "上级部门id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fk_header_id", value = "部门负责人id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fk_contacts_id", value = "部门联系人id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "telephone", value = "联系电话", required = true, paramType = "query"),
            @ApiImplicitParam(name = "functions", value = "部门智能", required = true, paramType = "query"),
            @ApiImplicitParam(name = "order_code", value = "排序", required = true, paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", required = true, paramType = "query"),
            @ApiImplicitParam(name = "memo", value = "备注", required = true, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = false, paramType = "query")
    })
    @RequestMapping("/updateSysDeptById")
    @ResponseBody
    public BaseModel updateSysDeptById(SysDept sysDept, SysOrgan sysOrgan, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysDeptService.updateSysDeptById(sysDept, sysOrgan, baseModel, request);
    }

    @ApiOperation(value = "分页查询部门", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前查询页数（不填写则为首页）", required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量（默认为10条每页）", required = false, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, paramType = "query"),
            @ApiImplicitParam(name = "fk_parent_id", value = "上级部门id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "fk_header_id", value = "部门负责人id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "fk_contacts_id", value = "部门联系人id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "telephone", value = "联系电话", required = false, paramType = "query"),
            @ApiImplicitParam(name = "functions", value = "部门智能", required = false, paramType = "query"),
            @ApiImplicitParam(name = "order_code", value = "排序", required = false, paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", required = false, paramType = "query"),
            @ApiImplicitParam(name = "memo", value = "备注", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_user_id", value = "创建用户id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_user_name", value = "创建用户名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_time_start", value = "创建时间开始标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_time_end", value = "创建时间结束标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_user_id", value = "更新用户id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_user_name", value = "更新用户名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_time_start", value = "更新时间开始标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_time_end", value = "更新时间结束标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "getByPage", value = "是否需要分页查询（只要有值就不是分页查询）", required = false, paramType = "query")
    })
    @RequestMapping("/getSysDepts")
    @ResponseBody
    public BaseModel getSysDepts(PageInfo<?> pageInfo, SysDept sysDept, SysOrgan sysOrgan, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysDeptService.getSysDepts(pageInfo, sysDept, sysOrgan, baseModel, request);
    }

    @ApiOperation(value = "绑定部门与单位", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dept_id", value = "部门id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = true, paramType = "query"),
    })
    @RequestMapping("/bindDeptAndOrgan")
    @ResponseBody
    public BaseModel bindDeptAndOrgan(SysDept sysDept, SysOrgan sysOrgan, BaseModel baseModel, HttpServletRequest request) throws Exception {
        return sysDeptService.bindDeptAndOrgan(sysDept,sysOrgan,baseModel,request);
    }

    @ApiOperation(value = "解除部门与单位之间的联系", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dept_id", value = "部门id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = true, paramType = "query"),
    })
    @RequestMapping("/deleteBindDeptAndOrgan")
    @ResponseBody
    public BaseModel deleteBindDeptAndOrgan(SysDept sysDept, SysOrgan sysOrgan, BaseModel baseModel, HttpServletRequest request) throws Exception {
        return sysDeptService.deleteBindDeptAndOrgan(sysDept,sysOrgan,baseModel,request);
    }


}
